package com.inspector.app.ui.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.inspector.app.R;
import com.inspector.app.ui.chat.adapter.MenuAdapter;
import com.inspector.app.ui.chat.entity.MenuEntity;

import java.util.ArrayList;

public class MorePanel extends LinearLayout implements MenuAdapter.OnItemClickListener, View.OnClickListener {
    private View inflate;


    private static RelativeLayout relativeExtArea;

    private static LinearLayout extView;

    private RecyclerView optionsRv;

    private ArrayList<MenuEntity> mList = new ArrayList<>();
    private MenuAdapter adapter;


    private OnMorePanelListener mListener;


    public MorePanel(Context context) {
        this(context, null);
    }

    public MorePanel(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MorePanel(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
        initData();
    }

    public void setOnOnMorePanelListener(OnMorePanelListener listener) {
        this.mListener = listener;
    }


    public static LinearLayout getExtView() {
        return extView;
    }


    @SuppressLint("ResourceAsColor")
    private void initView() {
        inflate = LayoutInflater.from(getContext()).inflate(R.layout.more_panel_view, this, true);
        relativeExtArea = findViewById(R.id.relative_ext_area);
        extView = findViewById(R.id.linear_ext_view);
        optionsRv = findViewById(R.id.more_options_rv);
        optionsRv.setLayoutManager(new GridLayoutManager(getContext(), 4));
        adapter = new MenuAdapter();
        optionsRv.setAdapter(adapter);
        adapter.setOnItemClickListener(this);
        relativeExtArea.setOnClickListener(this);//点击了面板中其他区域

    }


    private void initData() {
        mList.add(new MenuEntity(1, "相册", R.mipmap.photo_album_image));
        mList.add(new MenuEntity(2, "视频", R.mipmap.video_image));
        mList.add(new MenuEntity(3, "位置", R.mipmap.location_image));
        mList.add(new MenuEntity(4, "标会", R.mipmap.plotting_image));
        mList.add(new MenuEntity(5, "文件", R.mipmap.file_image));
        adapter.setData(mList);
    }


    @Override
    public void onItemClick(View view, int position) {
        switch (mList.get(position).getType()) {
            case 1:
                //打开相册
                if (mListener != null) {
                    mListener.showImage();
                }
                break;
            case 2:
                //拍摄视频
                if (mListener != null) {
                    mListener.showCamera();
                }
                break;
            case 3:
                //弹出位置
                if (mListener != null) {
                    mListener.showLocation();
                }
                break;
            case 4:
                //弹出标会
                if (mListener != null) {
                    mListener.showPlotting();
                }
                break;
            case 5:
                //选择文件
                if (mListener != null) {
                    mListener.showFile();
                }
                break;


        }

    }

    @Override
    public void onClick(View view) {

    }

    public interface OnMorePanelListener {
        void showImage();

        void showCamera();

        void showLocation();

        void showFile();

        void showPlotting();


    }
}
